package api

import (
	"net/http"

	"openzbox.com/frame/echo"
	"openzbox.com/gateway/core"
	"openzbox.com/utils"
)

/*保存配置*/
func SaveConfig(c echo.Context) error {
	info := utils.ResponseSuccess("保存成功.")
	u := new(core.Mbox)
	// 调用 echo.Context 的 Bind 函数将请求参数和 User 对象进行绑定。
	if err := c.Bind(u); err != nil {
		info.Code = 0
		info.Desc = "参数错误."
		return c.JSON(http.StatusOK, info)
	}
	core.Mybox.ID = u.ID
	core.Mybox.Email = u.Email
	core.Mybox.Manager = u.Manager
	core.Mybox.Mobile = u.Mobile
	core.Mybox.Maintenancer = u.Maintenancer

	ok, err := core.Mybox.SaveConfig()
	if ok {
		return c.JSON(http.StatusOK, info)
	} else {
		info.Desc = err.Error()
		info.Code = 0
		return c.JSON(http.StatusOK, info)
	}
}

/*读取配置文件*/
func GetConfig(c echo.Context) error {
	//conf := core.GetConfig()
	return c.JSON(http.StatusOK, core.Mybox)
}
